import request from 'umi-request';

export async function querySocialSecurityPlansPage(params = {},type) {
  return request('/hr-ssc/api/api-admin/security/getSecurityList', {
    method: 'post',
    data: {
      pageNum: params.current,
      ...params,
      type: type,
    },
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function addSecurityPlan(params) {
  return request(`/hr-ssc/api/api-admin/security/saveOrUpdateSecurity`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function delSecurityPlan(params) {
  return request(`/hr-ssc/api/api-admin/security/deleteSecurity`, {
    method: 'post',
    data: {
      typeId: params.securityId,
      type: 0
    },
    requestType: 'form'
  }).then((res) => {
    return res;
  });
}

export async function delSecurityItemPlan(itemId) {
  return request(`/hr-ssc/api/api-admin/security/deleteSecurityItem?itemId=${itemId}`, {
    method: 'delete',
  }).then((res) => {
    return res;
  });
}

export async function getItemBySecurityId(securityId) {
  return request(`/hr-ssc/api/api-admin/security/getItemBySecurityId`, {
    method: 'post',
    data: {securityId: securityId},
    requestType: 'form'
  }).then((res) => {
    if (res.flag){
      return res.data;
    }
    return [];
  });
}


export async function addSecurityUser(params) {
  return request(`/hr-ssc/api/api-admin/security/saveOrUpdateEmployeeSecurity`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function getSecurityEmployeeInfo(securityId) {
  return request(`/hr-ssc/api/api-admin/security/getSecurityEmployeeInfo`, {
    method: 'post',
    data: {securityId: securityId},
    requestType: 'form'
  }).then((res) => {
    if (res.flag){
      return res.data;
    }
    return [];
  });
}

export async function deleteEmployeeSecurity(employeeSecurityId,securityId,type,oid) {
  return request(`/hr-ssc/api/api-admin/security/deleteEmployeeSecurity`, {
    method: 'delete',
    params:{
      employeeSecurityId:employeeSecurityId,
      type: type,
      securityId: securityId,
      oid: oid
    }
  }).then((res) => {
    return res;
  });
}

export async function getSecurityRecordList(params,isConfirm,isCheck) {
  return request(`/hr-ssc/api/api-admin/security/getSecurityRecordList`, {
    method: 'post',
    data: {
      pageNum: params.current,
      pageSize: params.pageSize,
      isConfirm: isConfirm,
      isCheck: isCheck,
      ...params,
      operateTime: new Date(params.operateTime),
    },
  }).then((res) => {
    if (res.flag){
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    }
    return {};
  });
}

export async function getSecurityChangeList(params) {
  let { current, pageSize, operationTime, ...data } = params;
  return request(`/hr-ssc/api/api-admin/security/getSecurityChangeList`, {
    method: 'post',
    data: {
      pageNum: params.current,
      pageSize: params.pageSize,
      securityType: 0,
      operationTime: new Date(operationTime),
      ...data
    },
  }).then((res) => {
    if (res.flag){
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    }
    return {};
  });
}

export async function updateRecordStatus(data) {
  const {recordIds, ...restData} = data;
  return request(`/hr-ssc/api/api-admin/security/updateRecordStatus`, {
    method: 'post',
    data: {
      recordId: recordIds,
      ...restData,
      type: 0
    },
  }).then((res) => {
    return res;
  });
}

export async function saveMakeUp(params) {
  return request(`/hr-ssc/api/api-admin/security/supplementarySecurity`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function updateSecurityRecord(params) {
  return request(`/hr-ssc/api/api-admin/security/saveOrUpdateSecurityRecord`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function addDisabledOrLargerInfo(params) {
  return request(`/hr-ssc/api/api-admin/security/addDisabledOrLargerInfo`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function deleteSecurityRecord(recordId) {
  return request(`/hr-ssc/api/api-admin/security/deleteSecurityRecord`, {
    method: 'post',
    data: {recordId},
    requestType: 'form'
  }).then((res) => {
    return res;
  });
}

export async function exportSecurityRecord(recordIds) {
  return request(`/hr-ssc/api/api-admin/export/exportSecurityRecord`, {
    method: 'post',
    data: {recordIds},
    requestType: 'form',
    responseType: 'arrayBuffer'
  }).then((res) => {
    return res;
  });
}

export async function exportFundsRecord(recordIds) {
  return request(`/hr-ssc/api/api-admin/export/exportFundsRecord`, {
    method: 'post',
    data: {recordIds},
    requestType: 'form',
    responseType: 'arrayBuffer'
  }).then((res) => {
    return res;
  });
}

export async function removeAllRecord(unitId) {
  return request(`/hr-ssc/api/api-admin/security/deleteSecurityRecordAll`, {
    method: 'delete',
    data: {
      unitId,
    },
    requestType: 'form'
  }).then((res) => {
    return res;
  });
}

export async function removeRecordList(recordIds) {
  return request(`/hr-ssc/api/api-admin/security/deleteSecurityRecordByIds`, {
    method: 'delete',
    data: {
      recordIds,
    },
    requestType: 'form'
  }).then((res) => {
    return res;
  });
}

export async function refreshSecurityRecord(unitId,type) {
  //type 0社保，1公积金
  return request(`/hr-ssc/api/api-admin/security/refreshSecurityRecord`, {
    method: 'post',
    data: {unitId:unitId,type:type},
    requestType:'form'
  }).then((res) => {
    return res;
  });
}

